package org.bite.lesson11;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class Demo1103 {
    public static void main(String[] args) throws Exception {
        //初始化一个锁
        ReentrantLock lock = new ReentrantLock();
        try{
            lock.lock();
            System.out.println("执行业务……");
            TimeUnit.SECONDS.sleep(3);
            throw new Exception("执行出现异常");
        }finally{
            //要保证无论何时都能释放锁，放进finally中执行
            lock.unlock();
            System.out.println("释放了锁");
        }
    }
}
